package wc.servicelet; /**
 * @ClassName:${NAME}
 * @Author: 鹿建文
 * @Date: 2022/4/9  - 9:39
 * @Describe:
 */

import wc.domain.Admin;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.time.LocalDate;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@WebServlet(urlPatterns = "/fs")
public class FreemarkerServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setAttribute("title","Servlet整合Freemarker");
        request.setAttribute("msg","好好学习，天天向上！");
        request.getRequestDispatcher("/test.ftl").forward(request,response);
        Admin admin = new Admin(1001, "张三", "zhangsan", "1234", "fdajskfasjfk");
        request.setAttribute("admin",admin);

        List<String> list = List.of("aa","bb","cc","dd");
        request.setAttribute("list123",list);


        Map<String,Object> map = new HashMap<>();
        map.put("id",1002);
        map.put("nickname","李四");
        map.put("birth", LocalDate.now());
        request.setAttribute("map",map);

        request.setAttribute("age",78);

        request.setAttribute("user1","3333333333");
        request.setAttribute("user2",null);

        //请求转发，可以传递数据
        request.getRequestDispatcher("demo.ftl").forward(request,response);
    }


}
